package com.itHsuSE.experiment;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Experiment3_1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int dividend = 0; // 被除数
        int divisor = 0; // 除数

        while (true) {
            try {
                System.out.println("请输入被除数：");
                dividend = scanner.nextInt(); // 读取被除数
                System.out.println("请输入除数：");
                divisor = scanner.nextInt(); // 读取除数

                if (divisor == 0) {
                    throw new ArithmeticException("除数为0"); // 如果除数为0，则抛出算术异常
                }

                System.out.println("商：" + (dividend / divisor)); // 输出商
                break;
            } catch (InputMismatchException e) {
                System.out.println("输入的数据不合法，请重新输入整数："); // 捕获输入不合法的异常，并输出错误提示
                scanner.nextLine(); // 清空输入缓冲区
            } catch (ArithmeticException e) {
                System.out.println(e.getMessage()); // 捕获除数为0的异常，并输出错误提示
                break;
            }
        }
    }
}
